package com.lehuowujie.lehuomarket.ui;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.lehuowujie.lehuomarket.R;
import com.lehuowujie.lehuomarket.base.BaseActivity;
import com.lehuowujie.lehuomarket.fragment.IndicatorFragment;
import com.lehuowujie.lehuomarket.viewpagerindicator.ViewPagerIndicator;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 分类
 * Created by 王瑞铭 on 2017/1/16.
 */
public class CategoryActivity extends BaseActivity {

    private ViewPager mViewPager;
    private ViewPagerIndicator mIndicator;

    private List<String> mTitles = Arrays.asList("测试1", "测试测试2", "测试3测试测试", "测试4", "测试5", "测试测试6", "测试7", "测试8测试测试", "测试9");
    private List<IndicatorFragment> mFragments = new ArrayList<>();

    @Override
    public int setContentViewRes() {
        return R.layout.activity_category;
    }

    @Override
    public void initView() {
        initToolBar();
        setTitle(R.string.fragment_category);
        setBack(true);
        mViewPager = (ViewPager) findViewById(R.id.viewPager);
        mIndicator = (ViewPagerIndicator) findViewById(R.id.indicator);
    }

    @Override
    public void initEvent() {
        mIndicator.setList(mTitles);
        initViewPager();
        mIndicator.setViewPager(mViewPager, 0);
    }

    private void initViewPager() {
        for (String title : mTitles) {
            IndicatorFragment fragment = IndicatorFragment.newInstance(title);
            mFragments.add(fragment);
        }
        mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return mFragments.get(position);
            }

            @Override
            public int getCount() {
                return mFragments.size();
            }
        });
    }

}
